package com.cyc.gulimall.search.controller;

import com.cyc.common.to.es.SkuEsModel;
import com.cyc.common.utils.R;
import com.cyc.gulimall.search.service.ProductSaveService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

import java.io.IOException;
import java.util.List;

@RestController
@RequestMapping("/search/save")

public class ElasticSaveController {
    @Autowired
    ProductSaveService productSaveService;

    @PostMapping("/product")
    public R productStatusUp(@RequestBody List<SkuEsModel> skuEsModels){

        boolean b=false;
        try {
            b=productSaveService.productStatusUp(skuEsModels);
        } catch (IOException e) {
            return R.error(11100,"商品上架异常");
        }

        if (!b){
            return R.ok();
        }else {
            return R.error(11100,"商品上架异常");
        }


    }

}
